#include "SymbolTable.h"
#include<iostream>

void SymbolTable::addSymbol(std::string& sName, Symbol::Type eSymbolType)
{
	Symbol xSymbol;

	xSymbol.m_sName = sName;
	xSymbol.m_eSymbolType = eSymbolType;

	addSymbol(xSymbol);
}

void SymbolTable::addSymbol(Symbol& xSymbol)
{
	Symbol* pxSymbol = new Symbol();
	*pxSymbol = xSymbol;
	pxSymbol->m_pxScope = m_pxOwnerScope;

	m_apxSymbol.push_back(pxSymbol);
}

bool SymbolTable::isPresent(std::string& sCheckName, Symbol& out_xSymbol)
{
	Symbol xSymbol;

	xSymbol.m_sName = sCheckName;
	xSymbol.m_eSymbolType = Symbol::eSymbolInvalid;

	for(size_t i=0;i<m_apxSymbol.size();i++)
	{
		if( m_apxSymbol[i]->m_sName == sCheckName)
		{
			out_xSymbol = *m_apxSymbol[i];
			return true;
		}
	}

	return false;
}


void SymbolTable::print()
{
	int nSymbols = m_apxSymbol.size();
	using namespace std;

	for(int i=0; i<nSymbols; i++)
	{
		m_apxSymbol[i]->print();
	}

}

size_t SymbolTable::getSize()
{
	return m_apxSymbol.size();
}

